package cate.game.activity.battleroyale;

import cate.game.activity.base.core.ActivityGlobalData;
import cate.game.activity.battleroyale.po.BattleRoyaleRecord;
import cate.game.activity.battleroyale.po.BattleRoyaleRecords;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

public class BattleRoyaleSPO extends ActivityGlobalData {
    @NoteField(value = "通关记录")
    public Map<Integer, BattleRoyaleRecords> recordMap;

    public BattleRoyaleSPO() {

    }

    @Override
    public void initialize() {
        super.initialize();
        if (recordMap == null) {
            recordMap = new HashMap<>();
        }
    }

    /** 获取指定层的记录(必定能获取到) */
    public BattleRoyaleRecord getRecord(int activityId, int charpter, int level) {
        synchronized (this) {
            BattleRoyaleRecords records = recordMap.computeIfAbsent(activityId, k -> new BattleRoyaleRecords());
            for (BattleRoyaleRecord r : records.recordList) {
                if (r.chapter == charpter && r.level == level) {
                    return r;
                }
            }
            BattleRoyaleRecord record = new BattleRoyaleRecord(charpter, level);
            records.recordList.add(record);
            return record;
        }
    }

    @Override
    public void clear() {
        recordMap.clear();
    }
}
